﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;
using System.Windows.Input;
using System.Collections.ObjectModel;

namespace DiagramDesigner
{

    public class CanvasTools : ObservableCollection<CanvasTool> {}

    public delegate void AddObjectEventHandler(object sender, AddObjectEventArgs e);
    
    public abstract class CanvasTool : DependencyObject
    {
        public event AddObjectEventHandler AddObjectEvent;
        abstract public void DragStarted(Point p);
        abstract public void DragCompleted(Point p);
        abstract public void MouseMove(Point p);
        abstract public void DragCanceled();
        //abstract public void RenderGraphic(DrawingContext dc);
        virtual public Cursor Cursor { get; protected set; }
    }


    public class CanvasToolAddLine : CanvasTool
    {
        bool isDragging = false;
        //private LineModel _lineModel = null;

        override public Cursor Cursor
        {
            get
            {
                return Cursors.Cross;
            }            
        }

        public LineModel InputLine
        {
            get { return (LineModel)GetValue(InputLineProperty); }
            set { SetValue(InputLineProperty, value); }
        }

        // Using a DependencyProperty as the backing store for InputLine.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty InputLineProperty =
            DependencyProperty.Register("InputLine", typeof(LineModel), typeof(CanvasTool), new UIPropertyMetadata(null));
       

        override public void DragStarted(Point p)
        {
            LineModel lm = InputLine;
            if (lm == null)
                lm = new LineModel();

            lm.Pt1 = p;
            lm.Pt2 = p;

            InputLine = lm;
            //if (AddObjectEvent != null)
            //    AddObjectEvent(this, new AddObjectEventArgs(_lineModel));

            isDragging = true;
        }

        override public void DragCompleted(Point p)
        {
            if (InputLine != null && InputLine.Pt1 == InputLine.Pt2)
                InputLine = null;            
            
            isDragging = false;
        }
        override public void MouseMove(Point p)
        {
            if (isDragging && InputLine != null)
            {
                InputLine.Pt2 = p;
            }
        }
        override public void DragCanceled()
        {
            isDragging = false;                      
        }

        //override public void RenderGraphic(DrawingContext dc)
        //{
        //    //if (isDragging)
        //    //    dc.DrawLine(LinePen, ptStart, ptEnd);
        //}
    }
}
